package yo.latyoo.hokage.skmr.configuration;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import yo.latyoo.hokage.skmr.biz.repository.JobGroupRepo;
import yo.latyoo.hokage.skmr.biz.repository.JobInfoRepo;
import yo.latyoo.hokage.skmr.biz.repository.JobLogRepo;
import yo.latyoo.hokage.skmr.biz.repository.JobRegistryRepo;
import yo.latyoo.hokage.skmr.biz.service.email.EmailProvider;

import javax.sql.DataSource;

@Component
public class SkmrConfiguration implements InitializingBean, DisposableBean {

    private static SkmrConfiguration config = null;
    private SchedulerConfiguration schedulerConfiguration;
    private SkmrConfiguration(){}
    public static SkmrConfiguration getConfig() { return config; }


    @Override
    public void afterPropertiesSet() throws Exception {
        config = this;
        schedulerConfiguration = new SchedulerConfiguration();
        schedulerConfiguration.init();

    }

    @Override
    public void destroy() throws Exception {
        schedulerConfiguration.destroy();
    }

    @Resource
    private JobGroupRepo jobGroupRepo;

    @Resource
    private JobInfoRepo jobInfoRepo;
    @Resource
    private JobLogRepo jobLogRepo;
    @Resource
    private JobRegistryRepo jobRegistryRepo;

    @Resource
    private DataSource dataSource;

   // @Resource
    //private JobProperties jobProperties;

    @Resource
    private EmailProvider emailProvider;

    public JobGroupRepo getJobGroupRepo(){
        return jobGroupRepo;
    }

    public JobInfoRepo getJobInfoRepo(){
        return jobInfoRepo;
    }

    public JobLogRepo getJobLogRepo() {
        return jobLogRepo;
    }

    public JobRegistryRepo getJobRegistryRepo() {
        return jobRegistryRepo;
    }

    public DataSource getDataSource() {
        return dataSource;
    }

   /* public String getAccessToken(){
        return jobProperties.getAccessToken();
    }
    public Integer getLogRetentionDays(){
        return jobProperties.getLogRetentionDays();
    }
*/
    public EmailProvider getEmailProvider() {
        return emailProvider;
    }
}
